package com.example.music_project.fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.music_project.R;
import com.example.music_project.adapter.SocialPostAdapter;
import com.example.music_project.entity.SocialPost;

import java.util.ArrayList;
import java.util.List;

public class SocialFragment extends Fragment {

    private RecyclerView recyclerView;
    private SocialPostAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_social, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        recyclerView = view.findViewById(R.id.recycler_social);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        adapter = new SocialPostAdapter();
        recyclerView.setAdapter(adapter);

        // 加载模拟数据
        loadSocialPosts();
    }

    private void loadSocialPosts() {
        List<SocialPost> posts = new ArrayList<>();
        posts.add(new SocialPost("音乐达人", "分享了一首好听的歌", "3分钟前", R.drawable.user, R.drawable.sea));
        posts.add(new SocialPost("歌迷小明", "求这首歌曲的伴奏资源~", "1小时前", R.drawable.user, R.drawable.baibai));
        posts.add(new SocialPost("吉他高手", "上传了我的翻唱作品", "5小时前", R.drawable.user, R.drawable.clear_day));

        adapter.setPosts(posts);
    }
}